<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#fff"
            :text-color="textColor" :active-text-color="maincolor?maincolor:activeColor" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import {mapState} from 'vuex'
    import bus from '../common/bus';
    export default {
        data() {
            return {
                collapse: false,
                textColor: "#545454",
                activeColor: "#20a0ff",
                items: [
                    {
                        icon: 'home',
                        index: 'dashboard',
                        title: '首页'
                    },
                    {
                        icon: 'setting',
                        index: '1',
                        title: '系统工具',
                        subs:[
                            {
                                index: 'basic',
                                title: '基础设置'
                            },
                            {
                                index: 'email',
                                title: '邮件设置'
                            },
                            {
                                index: 'datalink',
                                title: '数据链接设置'
                            },
                            {
                                index: 'updatepassword',
                                title: '修改密码'
                            },
                        ]
                    },
                    {
                        icon: 'service',
                        index: '8',
                        title: '权限管理',
                        subs:[
                            {
                                index: 'departmentset',
                                title: '组织设置'
                            },
                            {
                                index: 'ruleset',
                                title: '角色设置'
                            },
                            {
                                index: 'responsiblityset',
                                title: '职责设置'
                            },
                            {
                                index: 'userset',
                                title: '用户设置'
                            }
                            // {
                            //     index: 'assignment',
                            //     title: '权限分配'
                            // }
                        ]
                    },
                    // {
                    //     icon: 'el-icon-refresh',
                    //     index: '3',
                    //     title: '表盘设置',
                    //     subs:[
                    //         {
                    //             index: 'colorcase',
                    //             title: '配色方案'
                    //         }
                    //     ]
                    // },
                    {
                        icon: 'view',
                        index: '4',
                        title: '数据监控',
                        subs:[
                            // {
                            //     index: 'portmonitor',
                            //     title: '预定义接口监控'
                            // },
                            {
                                index: 'dashboardset',
                                title: '表盘类型设置'
                            },
                            {
                                index: 'sqlsetting',
                                title: '表盘SQL设置'
                            },
                            // {
                            //     index: 'savesetting',
                            //     title: '存储过程设置'
                            // },
                            // {
                            //     index: 'filesetting',
                            //     title: '表盘文档设置'
                            // },
                        ]
                    },
                    // {
                    //     icon: 'el-icon-document',
                    //     index: '5',
                    //     title: '文件监控',
                    //     subs:[
                    //         {
                    //             index: 'ftpmanage',
                    //             title: 'FTP服务器管理'
                    //         },
                    //         {
                    //             index: 'servermanage',
                    //             title: '文件服务器管理'
                    //         },
                    //         {
                    //             index: 'filemonitor',
                    //             title: '文件监控设置'
                    //         },
                    //         {
                    //             index: 'batch',
                    //             title: 'BATCH文件设置'
                    //         },
                    //     ]
                    // },
                    {
                        icon: 'phone',
                        index: '6',
                        title: '即时通讯集成',
                        subs:[
                            {
                                index: 'pushsetting',
                                title: '推送接口设置'
                            }
                        ]
                    },
                    {
                        icon: 'sort',
                        index: '7',
                        title: '任务调度',
                        subs:[
                            {
                                index: 'frequency',
                                title: '任务调度频率'
                            },
                            {
                                index: 'dispatchtask',
                                title: '调度任务'
                            },
                            // {
                            //     index: 'savesetting2',
                            //     title: '存储过程设置'
                            // },
                            {
                                index: 'logmanage',
                                title: '调度任务日志管理'
                            },
                        ]
                    },
                ]
            }
        },
        mounted() {
            this.hideUpdatePwd();
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            },
            ...mapState({
                maincolor: state => state.system.colors,
            })
        },
        methods: {
            hideUpdatePwd() {
                if(localStorage.getItem('userType') == "1") {
                    this.items[1].subs = this.items[1].subs.slice(0,3);
                }
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 46px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 249px;
    }
    .sidebar > ul {
        height:100%;
    }
    .el-menu-item i{
        width: 20px;
        height: 20px;
        display: inline-block;
        background-size: 96%;
        margin: 0 10px 0 4px;
    }
    .el-submenu__title i{
        width: 20px;
        height: 20px;
        display: inline-block;
        background-size: 96%;
        margin: 0 10px 0 4px;
    }
    .home{
        background: url('../../assets/images/icon1.png') 0 0 no-repeat;
    }
    .setting{
        background: url('../../assets/images/icon2.png') 0 0 no-repeat;
    }
    .service{
        background: url('../../assets/images/icon3.png') 0 0 no-repeat;
    }
    .view{
        background: url('../../assets/images/icon4.png') 0 0 no-repeat;
    }
    .phone{
        background: url('../../assets/images/icon5.png') 0 0 no-repeat;
    }
    .sort{
        background: url('../../assets/images/icon6.png') 0 0 no-repeat;
    }
</style>
